package com.east.service.department.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.east.bean.Department;
import com.east.bean.DictionaryItems;
import com.east.controller.department.DepartmentTree;
import com.east.dao.DepartmentMapper;
import com.east.service.department.DepartmentService;
import com.east.utils.ObjectUtil;
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService{
	@Autowired
	DepartmentMapper departmentMapper;
	@Override
	public List<DepartmentTree> findTree() {
		List<DepartmentTree> children=new ArrayList<DepartmentTree>();
		DepartmentTree departmentTree = new DepartmentTree();
		departmentTree.setLabel("网信科技");
		departmentTree.setdId(null);
		departmentTree.setChildren(departmentMapper.findTree());
		children.add(departmentTree);
		return children;
	}
	@Override
	public Department findByDepartment(Department department) {
		// TODO Auto-generated method stub
		return departmentMapper.selectByPrimaryKey(department.getdId());
	}
	@Override
	public int saveDepartMent(Department department) {
		Department dpar = new Department();
		dpar.setdDecription(department.getdDecription());
		dpar.setdName(department.getdName());
		dpar.setdSerialNum("bm"+ObjectUtil.serNum());
		dpar.setdPId(department.getdPId());
		return departmentMapper.insert(dpar);
	}
	@Override
	public int updateDepartMent(Department department) {
		Department dpar = departmentMapper.selectByPrimaryKey(department.getdId());
		dpar.setdDecription(department.getdDecription());
		dpar.setdName(department.getdName());
		return departmentMapper.updateByPrimaryKey(dpar);
	}
	@Override
	public int delDepartMent(Department department) {
		return departmentMapper.deleteByPrimaryKey(department.getdId());
	}
	@Override
	public List<DictionaryItems> findAll() {
		return departmentMapper.findAllDiction();
	}

}
